cd "F:\Dropbox\School\Research Projects\Populism\Articles\Populist Psychology\Submission files\JOP 2020\Final\Replication files"

use "study 1 prepped.dta", clear

*Preacher and Hayes mediation
gen ang_t = .
replace ang_t = 0 if treat==0
replace ang_t = 1 if treat==2

sureg (anger ang_t) (fear ang_t) (cultdisc ang_t anger fear)

capture program drop bootmm
program bootmm, rclass
  syntax [if] [in]
  sureg (anger ang_t) (fear ang_t) (cultdisc ang_t anger fear) `if' `in'
  return scalar indang  = [anger]_b[ang_t]*[cultdisc]_b[anger]
  return scalar indfear  = [fear]_b[ang_t]*[cultdisc]_b[fear]
  return scalar indtotal = [anger]_b[ang_t]*[cultdisc]_b[fear]+[anger]_b[ang_t]*[cultdisc]_b[fear]
  end
  
  bootstrap r(indang) r(indfear) r(indtotal), bca reps(5000): bootmm
  *Ratio - indirect to direct

  *Ratio - indirect to direct

display  .0425636  /.0064965  

*Proportion mediated
 display  .0425636  /(.0425636   + .0064965   )

sureg (anger ang_t) (fear ang_t) (idmarg ang_t anger fear)

capture program drop bootmm
program bootmm, rclass
  syntax [if] [in]
  sureg (anger ang_t) (fear ang_t) (idmarg  ang_t anger fear) `if' `in'
  return scalar indang  = [anger]_b[ang_t]*[idmarg ]_b[anger]
  return scalar indfear  = [fear]_b[ang_t]*[idmarg ]_b[fear]
  return scalar indtotal = [anger]_b[ang_t]*[idmarg ]_b[fear]+[anger]_b[ang_t]*[idmarg ]_b[fear]
  end
  
  bootstrap r(indang) r(indfear) r(indtotal), bca reps(5000): bootmm
  *Ratio - indirect to direct

  *Ratio - indirect to direct

display  .0381065   / .0068167 

*Proportion mediated
 display  .0381065  /(.0381065    + .0068167   ) 
